/* 
 * File:   Field.cpp
 * Author: Pouja
 * 
 * Created on 17 august 2012, 14:00
 */

#include "Field.h"
#include "Hand.h"

const int Field::MAX_MONSTERCARDS=5;
const int Field::MAX_SPELLTRAPCARDS=5;

Field::Field(){
    fieldCard=NULL;
    monsterCards=new Deck();
    graveyard=new Deck();
    extraDeck=new Deck();
    spellTrapCards=new Deck();
    deck=new Deck();
    removeDeck=new Deck();
    hand=new Deck();
}

void Field::placeFieldCard(SpellTrapCard* fCard){
    removeFieldCard();
    fieldCard=fCard;
}

void Field::removeFieldCard(){
    fieldCard=NULL;
}

SpellTrapCard* Field::getFieldCard(){
    if(fieldCardPresent()){
        return dynamic_cast<SpellTrapCard*> (fieldCard);
    }
    return NULL;
}

bool Field::fieldCardPresent(){
    return(fieldCard!=NULL);
}

void Field::placeMonsterCard(MonsterCard* monsterCard){
    if(canPlaceMonsterCard()){
        monsterCards->addCard(monsterCard);
    }
}

MonsterCard* Field::getMonsterCard(MonsterCard* monsterCard){
    return dynamic_cast<MonsterCard*> (*(monsterCards->find(monsterCard)));
}

bool Field::canPlaceMonsterCard(){
    return monsterPlaced()<=Field::MAX_MONSTERCARDS;
}

int Field::monsterPlaced(){
    return monsterCards->size();
}

void Field::removeMonsterCard(MonsterCard* card){
    monsterCards->removeCard(card);
}

void Field::removeMonsterCard(int pos){
    monsterCards->removeCard(monsterCards->findN(pos));
}

MonsterCard* Field::getMonsterCard(int pos){
    return (dynamic_cast<MonsterCard*> (monsterCards->findN(pos)));
}

<<<<<<< .mine
const int Field::MAX_MONSTERCARDS=5;
const int Field::MAX_SPELLTRAPCARDS=5;

Field::Field(){
    fieldCard=NULL;
    graveyard=NULL;
    extraDeck=NULL;
    deck=NULL;
}

void Field::placeFieldCard(SpellTrapCard* fCard){
    removeFieldCard();
    fieldCard=fCard;
}

void Field::removeFieldCard(){
    if(fieldCardPresent()){
        addToGraveyard(fieldCard);
    }
=======
void Field::addToGraveyard(Card* card){
    graveyard->addCard(card);
}
Card* Field::getFromGraveyard(Card* card){
    return *(graveyard->find(card));
}
void Field::removeFromGraveyard(Card* card){
    graveyard->removeCard(card);
}
int Field::cardsInGraveyard(){
    return graveyard->size();
>>>>>>> .r45
}

<<<<<<< .mine
SpellTrapCard* Field::getFieldCard(){
    if(fieldCardPresent()){
        return fieldCard;
    }
    return NULL;
=======
void Field::setExtraDeck(Deck* deck){
    delete extraDeck;
    extraDeck=deck;
}
void Field::removeExtraDeck(Card* card){
    extraDeck->removeCard(card);
}
Card* Field::getFromExtraDeck(Card* card){
    return *(extraDeck->find(card));
}
int Field::cardsInExtraDeck(){
    return extraDeck->size();
>>>>>>> .r45
}

<<<<<<< .mine
bool Field::fieldCardPresent(){
    return(fieldCard!=NULL);
=======
void Field::setRemoveDeck(Deck* deck){
    delete removeDeck;
    removeDeck=deck;
}
void Field::removeRemoveDeck(Card* card){
    removeDeck->removeCard(card);
}
Card* Field::getFromRemoveDeck(Card* card){
    return *(removeDeck->find(card));
}
int Field::cardsInRemoveDeck(){
    return removeDeck->size();
>>>>>>> .r45
}

<<<<<<< .mine
void Field::placeMonsterCard(MonsterCard* monsterCard){
    if(canPlaceMonsterCard()){
        monsterCards.push_front(monsterCard);
    }
=======
void Field::placeSpellMagicCard(SpellTrapCard* spellTrapCard){
    if(canPlaceSpellMagicCard()){
        spellTrapCards->addCard(spellTrapCard);
    }
}
void Field::removeSpellMagicCard(SpellTrapCard* spellTrapCard){
    spellTrapCards->removeCard(spellTrapCard);
}
void Field::removeSpellMagicCard(int pos){
    spellTrapCards->removeCard(spellTrapCards->findN(pos));
}
bool Field::canPlaceSpellMagicCard(){
    return spellMagicPlaced()<=Field::MAX_SPELLTRAPCARDS;
}
SpellTrapCard* Field::getSpellMagicCard(SpellTrapCard* spellTrapCard){
    return dynamic_cast<SpellTrapCard*> (*(spellTrapCards->find(spellTrapCard)));
}
SpellTrapCard* Field::getSpellMagicCard(int pos){
    return dynamic_cast<SpellTrapCard*> (spellTrapCards->findN(pos));
}
int Field::spellMagicPlaced(){
    return spellTrapCards->size();
>>>>>>> .r45
}

<<<<<<< .mine
MonsterCard* Field::getMonsterCard(MonsterCard*){
    
=======
void Field::setDeck(Deck* deck){
    delete deck;
    this->deck=deck;
}
Card* Field::drawFromDeck(){
    return deck->drawCard();
>>>>>>> .r45
}

<<<<<<< .mine
bool Field::canPlaceMonsterCard(){
    return monsterPlaced()<=Field::MAX_MONSTERCARDS;
=======
void Field::removeFromDeck(Card* card){
    deck->removeCard(card);
>>>>>>> .r45
}
<<<<<<< .mine

int Field::monsterPlaced(){
    return monsterCards.size();
=======

void Field::removeFromDeck(int pos){
    removeFromDeck(deck->findN(pos));
>>>>>>> .r45
}

<<<<<<< .mine
void Field::addToGraveyard(Card*){
    
}
Card* Field::getFromGraveyard(Card*){
    
}
Card* Field::drawFromGraveyard(Card*){
    
=======
Card* Field::getFromDeck(Card* card){
    return *(deck->find(card));
}
int Field::cardsInDeck(){
    return deck->size();
>>>>>>> .r45
}
<<<<<<< .mine
int Field::cardsInGraveyard(){
    
=======

void Field::setHand(Deck* hand){
    delete hand;
    this->hand=hand;
>>>>>>> .r45
}

<<<<<<< .mine
void Field::setExtraDeck(Deck*){
    
}
Card* Field::drawExtraDeck(Card*){
    
}
Card* Field::getFromExtraDeck(Card*){
    
=======
void Field::removeFromHand(Card* card){
    hand->removeCard(card);
>>>>>>> .r45
}
<<<<<<< .mine
int Field::cardsInExtraDeck(){
    
=======

void Field::removeFromHand(int pos){
    hand->removeCard(hand->findN(pos));
>>>>>>> .r45
}

<<<<<<< .mine
void Field::placeSpellMagicCard(Card*){
    
}
Card* Field::getSpellMagicCard(Card*){
    
=======
Card* Field::getFromHand(Card* card){
    return *(hand->find(card));
>>>>>>> .r45
}
<<<<<<< .mine
int Field::SpellMagicPlaced(){
    
=======
int Field::cardsInHand(){
    return hand->size();
>>>>>>> .r45
}

<<<<<<< .mine
void Field::setDeck(Deck*){
    
}
Card* Field::drawFromDeck(Card*){
    
}
Card* Field::drawFromDeck(){
    
}
Card* Field::getFromDeck(Card*){
    
}
int Field::cardsInDeck(){
    
=======
Deck* Field::getZone(Field::zones zone){
    switch(zone){
        case DECK: return deck;
        case FIELD: return NULL;
        case MONSTER: return monsterCards;
        case GRAVEYARD: return graveyard;
        case SPELLTRAP: return spellTrapCards;
        case EXTRADECK: return extraDeck;
        case HAND: return hand;
        case REMOVEDECK: return removeDeck;
        default: return NULL;
    }
>>>>>>> .r45
}
<<<<<<< .mine

Field::~Field(){
    monsterCards.clear();
    spellTrapCards.clear();
=======

void Field::move(Card* card, Field::zones from, Field::zones to){
    if(from==FIELD&&to!=FIELD){
        getZone(to)->addCard(fieldCard);
        removeFieldCard();
    }
    else if(from!=FIELD&&to==FIELD){
        /*if(*(getZone(to)->find(card))==SPELLTRAPCARD){
            placeFieldCard(*(getZone(to)->find(card)));
            getZone(to)->removeCard(card);
       }*/
    }
    else{
        getZone(to)->addCard(*(getZone(from)->find(card)));
        getZone(from)->removeCard(card);
    }
>>>>>>> .r45
}

<<<<<<< .mine
=======
Field::~Field(){
    delete monsterCards;
    delete graveyard;
    delete extraDeck;
    delete spellTrapCards;
    delete deck;
}

>>>>>>> .r45
